<!--
 * @Author: coocase
 * @Date: 2021-05-14 15:15:41
 * @LastEditTime: 2021-06-11 11:49:11
 * @LastEditors: coocase
 * @Description: 
 * @FilePath: \git\dami\src\pages\index\main.vue
-->
<template>
    <div>
       
            <div class="wrapper">
                <search v-on:getResults="getResults"></search>
            </div>

            <!-- 绑定监听方法，监听子组件 获取index的userName      绑定数据给子组件-->
            <!-- 前一个是监听的子组件的方法，后一个是返回参数处理的方法 -->
            <router-view
                v-on:indexName="indexName"
                @getBuyInfo="getBuyInfo"
                :results="results"
            ></router-view>
            <foot></foot>
        
    </div>
</template>

<script>
import Search from "@/components/search";
import Foot from "@/components/footer";
import bus from "../../common/eventBus";
export default {
    name: "Main",
    components: {
        Search,
        Foot,
    },
    data() {
        return {
            name: "",
            results: "",
            paydatas: "",
        };
    },
    // beforeCreate: function () {
    //     console.log("beforeCreate");
    // },
    // created: function () {
    //     console.log("created");
    // },
    // mounted: function () {
    //     console.log("mounted");
    // },
    // beforeUpdate: function () {
    //     console.log("beforeUodate");
    // },
    beforeDestroy() {
        bus.$emit("buydatas", this.paydatas);
    },
    methods: {
        //监听子组件的方法 参数为子组件传的值
        indexName: function (val) {
            this.name = val;
            this.$emit("indexName", this.name);
            console.log("main name");
        },
        //监听子组件的方法 参数为子组件传的值
        getResults: function (val) {
            this.results = val;
        },
        getBuyInfo: function (datas) {
            this.paydatas = datas;
        },
        //
    },
};
</script>

<style scoped>
.wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
}

</style>